package dgut.party.business.dao.user;

import dgut.party.business.entity.base.Account;
import dgut.party.business.entity.user.NormalUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AccountRepository extends JpaRepository<Account, Long> {

  @Query("select DISTINCT a from Account a Left Join Fetch a.roles where username = :username or phone= :username")
  List<Account> findByUsernameJoinRole(@Param("username") String username);

  @Query("select DISTINCT a from Account a Left Join Fetch a.roles, Authority where username = :username or phone= :username")
  List<Account> findByUsernameJoinRoleAuthority(@Param("username") String username);

  List<Account> findByUsernameOrPhone(String username, String phone);

  Account findByPhone(String phone);

  List<Account> findByWeixin(String weixin);

  List<Account> findByQq(String qq);

  List<Account> findByRealName(String realName);

  Page<Account> findByRealName(String realName, Pageable pageable);

  List<Account> findByType(String type);

  Page<Account> findByType(String type, Pageable pageable);

  @Query("select a from Account a where a.type = 'NormalUser'")
  List<NormalUser> findAllNormalUser();
}
